﻿using ShaderCompiler.Core;

namespace ShadersCS
{
	public sealed class Normal : BaseVS
	{
		[ArrayType(8)]
		public Vector2[] sampleOffsets;
		public Texture2D MyTexture;

		[ShaderMethod(ShaderMethodTypes.PS)]
		public void mainPS()
		{
			Vector4 color = MyTexture.Sample(Texcoord_VSPS);
			color = (color-0.5) * 2.0;

			Vector3 normal = new Vector3();
			for (int i = 0; i != 8; ++i)
			{
				Vector2 offset = sampleOffsets[i];
				Vector4 block = MyTexture.Sample(Texcoord_VSPS + (offset * simulateSize));
				block = (block-0.5) * 2.0;

				Vector3 vec = new Vector3(offset, block.z-color.z);
				Vector3 up = new Vector3(0, 0, 1);

				up = SL.Cross(vec, up);
				normal += SL.Cross(vec, up);
			}
			normal = -SL.Normalize(normal);
			Color_PS = new Vector4((normal+1.0) * 0.5, 1);
		}
	}
}
